<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form :form="form" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-item label="collegeCode" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['collegeCode']" placeholder="请输入collegeCode"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="examineeCode" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['examineeCode']" placeholder="请输入examineeCode"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="stuName" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['stuName']" placeholder="请输入stuName"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="colleage" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['colleage']" placeholder="请输入colleage"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="eduBd" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['eduBd']" placeholder="请输入eduBd"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="grade" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['grade']" placeholder="请输入grade"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="trainCate" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['trainCate']" placeholder="请输入trainCate"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="sponsorPost" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['sponsorPost']" placeholder="请输入sponsorPost"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="major" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['major']" placeholder="请输入major"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="stuOriginPlace" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['stuOriginPlace']" placeholder="请输入stuOriginPlace"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="stuOriginPlaceCode" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['stuOriginPlaceCode']" placeholder="请输入stuOriginPlaceCode"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="agreementNum" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['agreementNum']" placeholder="请输入agreementNum"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="studyWork" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['studyWork']" placeholder="请输入studyWork"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="regSignCate" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['regSignCate']" placeholder="请输入regSignCate"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="regSignDept" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['regSignDept']" placeholder="请输入regSignDept"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="signDeptAddress" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['signDeptAddress']" placeholder="请输入signDeptAddress"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="signDeptPostalCode" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['signDeptPostalCode']" placeholder="请输入signDeptPostalCode"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="remarksPrintItem" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['remarksPrintItem']" placeholder="请输入remarksPrintItem"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="emplStatus" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['emplStatus']" placeholder="请输入emplStatus"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="unemplCate" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['unemplCate']" placeholder="请输入unemplCate"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="emplCate" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['emplCate']" placeholder="请输入emplCate"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="deptName" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['deptName']" placeholder="请输入deptName"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="socialCreditCode" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['socialCreditCode']" placeholder="请输入socialCreditCode"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="deptNature" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['deptNature']" placeholder="请输入deptNature"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="deptIndustry" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['deptIndustry']" placeholder="请输入deptIndustry"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="deptLocation" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['deptLocation']" placeholder="请输入deptLocation"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="deptLocationCode" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['deptLocationCode']" placeholder="请输入deptLocationCode"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="deptConsultant" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['deptConsultant']" placeholder="请输入deptConsultant"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="deptContactTel" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['deptContactTel']" placeholder="请输入deptContactTel"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="deptEmail" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['deptEmail']" placeholder="请输入deptEmail"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="positionCate" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['positionCate']" placeholder="请输入positionCate"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="deptAddress" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['deptAddress']" placeholder="请输入deptAddress"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="deptPostalCode" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['deptPostalCode']" placeholder="请输入deptPostalCode"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="fileForwardDeptName" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['fileForwardDeptName']" placeholder="请输入fileForwardDeptName"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="fileForwardDeptAddress" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['fileForwardDeptAddress']" placeholder="请输入fileForwardDeptAddress"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="fileForwardPostalCode" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['fileForwardPostalCode']" placeholder="请输入fileForwardPostalCode"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="fileForwardPostalTel" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['fileForwardPostalTel']" placeholder="请输入fileForwardPostalTel"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="accountTransferAddress" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['accountTransferAddress']" placeholder="请输入accountTransferAddress"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="expand6" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['expand6']" placeholder="请输入expand6"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="expand7" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['expand7']" placeholder="请输入expand7"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="expand8" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['expand8']" placeholder="请输入expand8"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="expand9" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['expand9']" placeholder="请输入expand9"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="expand10" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['expand10']" placeholder="请输入expand10"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="regCardNum" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['regCardNum']" placeholder="请输入regCardNum"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="operatTime" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['operatTime']" placeholder="请输入operatTime"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="reportNotes" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['reportNotes']" placeholder="请输入reportNotes"></a-input>
            </a-form-item>
          </a-col>
          <a-col v-if="showFlowSubmitButton" :span="24" style="text-align: center">
            <a-button @click="submitForm">提 交</a-button>
          </a-col>
        </a-row>
      </a-form>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import { validateDuplicateValue } from '@/utils/util'
  import JFormContainer from '@/components/jeecg/JFormContainer'

  export default {
    name: 'StudentForm',
    components: {
      JFormContainer,
    },
    props: {
      //流程表单data
      formData: {
        type: Object,
        default: ()=>{},
        required: false
      },
      //表单模式：true流程表单 false普通表单
      formBpm: {
        type: Boolean,
        default: false,
        required: false
      },
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        form: this.$form.createForm(this),
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/student/student/add",
          edit: "/student/student/edit",
          queryById: "/student/student/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        if(this.formBpm===true){
          if(this.formData.disabled===false){
            return false
          }
          return true
        }
        return this.disabled
      },
      showFlowSubmitButton(){
        if(this.formBpm===true){
          if(this.formData.disabled===false){
            return true
          }
        }
        return false
      }
    },
    created () {
      //如果是流程中表单，则需要加载流程表单data
      this.showFlowData();
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'collegeCode','examineeCode','stuName','colleage','eduBd','grade','trainCate','sponsorPost','major','stuOriginPlace','stuOriginPlaceCode','agreementNum','studyWork','regSignCate','regSignDept','signDeptAddress','signDeptPostalCode','remarksPrintItem','emplStatus','unemplCate','emplCate','deptName','socialCreditCode','deptNature','deptIndustry','deptLocation','deptLocationCode','deptConsultant','deptContactTel','deptEmail','positionCate','deptAddress','deptPostalCode','fileForwardDeptName','fileForwardDeptAddress','fileForwardPostalCode','fileForwardPostalTel','accountTransferAddress','expand6','expand7','expand8','expand9','expand10','regCardNum','operatTime','reportNotes'))
        })
      },
      //渲染流程表单数据
      showFlowData(){
        if(this.formBpm === true){
          let params = {id:this.formData.dataId};
          getAction(this.url.queryById,params).then((res)=>{
            if(res.success){
              this.edit (res.result);
            }
          });
        }
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            console.log("表单提交数据",formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'collegeCode','examineeCode','stuName','colleage','eduBd','grade','trainCate','sponsorPost','major','stuOriginPlace','stuOriginPlaceCode','agreementNum','studyWork','regSignCate','regSignDept','signDeptAddress','signDeptPostalCode','remarksPrintItem','emplStatus','unemplCate','emplCate','deptName','socialCreditCode','deptNature','deptIndustry','deptLocation','deptLocationCode','deptConsultant','deptContactTel','deptEmail','positionCate','deptAddress','deptPostalCode','fileForwardDeptName','fileForwardDeptAddress','fileForwardPostalCode','fileForwardPostalTel','accountTransferAddress','expand6','expand7','expand8','expand9','expand10','regCardNum','operatTime','reportNotes'))
      },
    }
  }
</script>